//
//  CGFileQueryCell.m
//  SchoolClient
//
//  Created by mac on 15/11/19.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CGFileQueryCell.h"

@implementation CGFileQueryCell

@synthesize loactionLabel,saveTimeLabel,updayTimeLabel;

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //档案位置
        CGRect aFrame = CGRectMake(0, 0, 80, 60);

        //存放时间
        aFrame.origin.x = 15;
//        aFrame.origin.y = 10;
        saveTimeLabel = [[UILabel alloc]initWithFrame:aFrame];
        saveTimeLabel.text = @"Nov 10, 2015 3:35:36 PM";
        saveTimeLabel.font = [UIFont systemFontOfSize:14];
        saveTimeLabel.textColor = [UIColor darkGrayColor];
        [self.contentView addSubview:saveTimeLabel];
        
        aFrame.origin.x = CGRectGetMaxX(saveTimeLabel.frame) + 10;
        aFrame.size.width = (SCREEN_WIDTH - 80*2 - 60);
        loactionLabel = [[UILabel alloc]initWithFrame:aFrame];
        loactionLabel.text = @"城市名";
        loactionLabel.font = [UIFont systemFontOfSize:16];
        loactionLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:loactionLabel];
        loactionLabel.numberOfLines = 0;
        
        //更新时间
        CGRect bFrame = CGRectMake(SCREEN_WIDTH - 100, 0, 80, 60);
//        aFrame.origin.y = saveTimeLabel.frame.origin.y;
//        aFrame.size.width = saveTimeLabel.width;
//        aFrame.origin.x = CGRectGetMaxX(loactionLabel.frame) + 10;
        updayTimeLabel = [[UILabel alloc]initWithFrame:bFrame];
        updayTimeLabel.text = @"Nov 10, 2015 3:35:36 PM";
        updayTimeLabel.font = [UIFont systemFontOfSize:14];
        updayTimeLabel.textColor = [UIColor darkGrayColor];
        updayTimeLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:updayTimeLabel];


    }
    return self;
}

-(void)setFileQuery:(CGFileQuery *)fileQuery{

    _fileQuery = fileQuery;
    loactionLabel.text = fileQuery.loaction;
    saveTimeLabel.text = [self getTimeWithDate:fileQuery.saveTime];
    updayTimeLabel.text = [self getTimeWithDate:fileQuery.updateTime];


}


-(NSString *)getTimeWithDate:(NSString *)timeStr{
    
    NSDateFormatter *inputFormatter = [[NSDateFormatter alloc]init];
    NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
    [inputFormatter setLocale:locale];
    [inputFormatter setDateFormat:@"MMM dd, yyyy hh:mm:ss aa"];
    NSDate *inputDate = [inputFormatter dateFromString:timeStr];
    //创建日期模板对象,设置模板的显示格式
    NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init];
    //outputFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
    outputFormatter.dateFormat = @"yyyy-MM-dd";
    NSString *outputDate = [outputFormatter stringFromDate:inputDate];     //自动转换成当地时间
    return outputDate;
}


@end
